public var cursor:Texture2D;
public var cursorPos: Vector3;

// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// *****************************************************
var newBoxTime: float;
var newBoxSetTime: float = 1.0;
var posArray: Vector3[];
var enemy: Transform;
var guiScreenTexture: Texture2D;
var guiStart: float;
var setPointFX: Transform;
private var guiSize: float;

public var levelTime: float;

public var playerCode: GamePlayerBehaviour;

function OnDrawGizmos() {
	for(var i: int = 0; i<posArray.length; i++){
			Gizmos.DrawIcon (posArray[i], "ZombiePoint.png");
	}
}

function Start() {
	Screen.showCursor = false;
	newBoxTime = newBoxSetTime;
	guiSize = guiScreenTexture.width;
	playerCode = target.GetComponent(GamePlayerBehaviour);	
}


function OnGUI() {
	cursorPos = Input.mousePosition;
	cursorPos.x -= 12;
	cursorPos.y = Screen.height - cursorPos.y-12;
	GUI.DrawTexture(Rect(cursorPos.x,cursorPos.y,24,24),cursor);
	guiStart = (Screen.width - guiSize) / 2.0;
	GUI.DrawTexture(Rect(guiStart,0,guiSize,76),guiScreenTexture);
	GUI.Label(Rect(guiStart,55,100,30),""+Mathf.RoundToInt(levelTime));
	GUI.Label(Rect(guiStart+54,55,100,30),""+playerCode.mainLife);
	GUI.Label(Rect(guiStart+108,55,100,30),"infinity");
	GUI.Label(Rect(guiStart+162,55,100,30),""+playerCode.miniGunCount);
	GUI.Label(Rect(guiStart+216,55,100,30),""+playerCode.shootGunCount);
	GUI.Label(Rect(guiStart+270,55,100,30),""+playerCode.bazukaCount);
	GUI.Label(Rect(0,0,100,30),CoreApplication.botCount+"/"+CoreApplication.botMaxCount);
}

function LateUpdate () {
	transform.position = target.position;
	transform.position -= Vector3.forward * distance;
	transform.position += Vector3.up * height;

	// Set the height of the camera
	//transform.position.y = currentHeight;
	
	// Always look at the target
	transform.LookAt (target);
}
function Update() {
	if(levelTime>0){
		levelTime -= Time.deltaTime;
		if(CoreApplication.botCount<CoreApplication.botMaxCount){
			newBoxTime -= Time.deltaTime;
			if(newBoxTime<=0){
				var index = Mathf.RoundToInt(Random.value * (posArray.length-1));
				CoreApplication.botCount++;
				newBoxTime = newBoxSetTime;
				var bot:Transform = Instantiate(enemy,posArray[index],Quaternion.identity);
				var setFx:Transform = Instantiate(setPointFX,posArray[index],Quaternion.identity);
				bot.GetComponent(GameBotBehaviour).SetTarget(target);
				print("bot" + CoreApplication.botCount);
			}
		}
		//
	}else{
		levelTime=0.0;
	}

}